from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
from django.db.models import Q


User = get_user_model()


class CustomBackend(ModelBackend):
    """自定义用户验证"""
    def authenticate(self, request, username=None, password=None, **kwargs):
        try:
            user = User.objects.get(
                Q(username=username) | Q(email=username))
            if user.check_password(password):
                return user

        except Exception as e:
            return None


# email 配置
REDIS_PASS = '1'
REDIS_HOST = ''
broker = 'redis://:{}@{}:6379/9'.format(REDIS_PASS, REDIS_HOST)
backend = 'redis://:{}@{}:6379/10'.format(REDIS_PASS, REDIS_HOST)







